#include "NavigationController.h"
#include <MainPage.h>
#include <BroswerPage.h>
#include <QWidget>
#include "VideoPage.h"
#include "MusicPage.h"
#include "WeatherPage.h"
#include "ImagePage.h"
#include "NavigationPage.h"
#include "ClientPage.h"

/**
 * @brief MyNavigationController::MyNavigationController
 * 导航类实现
 */
MyNavigationController::MyNavigationController(){
    qDebug() << "NavigationController init";
    // 初始化容器
    this->stackLayout = new QStackedLayout();

    // 初始化主界面
    MainPage *mainpage = new MainPage();
    this -> stackLayout -> addWidget(mainpage->getWidget());

    // 初始化浏览器界面
    BroswerPage *broswerpage = new BroswerPage();
    this -> stackLayout -> addWidget(broswerpage->getWidget());

    // 初始化视频界面
    VideoPage *videopage = new VideoPage();
    this-> stackLayout -> addWidget(videopage->getWidget());

    // 初始化音乐播放器界面
    MusicPage *musicpage = new MusicPage();
    this -> stackLayout -> addWidget(musicpage->getWidget());

    //初始化天气预报界面
    WeatherPage *weatherpage = new WeatherPage();
    this->stackLayout->addWidget(weatherpage->getWidget());

    //初始化图片浏览器界面
    ImagePage *imagepage = new ImagePage();
    this->stackLayout->addWidget(imagepage->getWidget());

    //初始化地图导航界面
    NavigationPage *navigationpage = new NavigationPage();
    this->stackLayout->addWidget(navigationpage->getWidget());
}

QStackedLayout * MyNavigationController::getStackLayout(){
    return this->stackLayout;
}

/**
 * @brief MyNavigationController::navigateToPage
 * @param destination
 * 实现跳转功能
 */
void MyNavigationController::navigateToPage(Route destination){
    //TODO
    switch(destination){
    case Route::Music:                  qDebug() << "music" ;           this ->stackLayout ->setCurrentIndex(3);    break;
    case Route::Navigation:             qDebug() << "navigation";       this ->stackLayout ->setCurrentIndex(6);    break;
    case Route::Communication:          qDebug() << "Communication";    break;
    case Route::Clock:                  qDebug() << "clock";            break;
    case Route::Weather:                qDebug() << "weather";          this ->stackLayout ->setCurrentIndex(4);    break;
    case Route::Video:                  qDebug() << "Video";            this ->stackLayout ->setCurrentIndex(2);    break;
    case Route::Photo:                  qDebug() << "photo";            this -> stackLayout ->setCurrentIndex(5);    break;
    case Route::Browser:                qDebug() << "Browser";          this -> stackLayout ->setCurrentIndex(1);    break;
    }
}

/**
 * @brief MyNavigationController::backToMainPage
 * 返回主页面
 */
void MyNavigationController::backToMainPage()
{
    this -> stackLayout -> setCurrentIndex(0);
}
